<template>
	<view>
		<scroll-view scroll-x class="bg-white nav tab-view" >
			<view class="flex text-center">
				<view class="flex-sub cu-item " :class="dtype == 1 ? 'text-blue cur':''" data-dtype="1"  @click.stop.prevent="tabSelect">
					广告
				</view>
				<view class="flex-sub cu-item" :class="dtype == 2 ? 'text-blue cur':''" data-dtype="2"  @click.stop.prevent="tabSelect">
					奖励
				</view>
				<view class="flex-sub cu-item" :class="dtype == 0 ? 'text-blue cur':''" data-dtype="0"  @click.stop.prevent="tabSelect">
					全部
				</view>
			</view>
		</scroll-view>
		<view style="height: 50px;"></view>
		<view class="cu-list menu-avatar" >
			<view class="cu-item" v-for="(item,index) in listData" :key="index">
				<view class="cu-avatar radius lg" style="background-image: url(http://image4.ailemon.cc/douyin-logo.jpeg)"></view>
				<view class="content">
					<view class="">
						<view class="text-cut">{{ item.flowNo }}</view>
					</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">{{ item.createTime }}</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-xs">{{ title }}</view>
					<view class="cu-tag round bg-red sm" v-if="item.status == 2 || item.status == 3">￥{{ item.money }}</view>
				</view>
			</view>

			<!--
		<view class="cu-item ">
			<view class="cu-avatar radius lg" style="background-image:url(https://ossweb-img.qq.com/images/lol/img/champion/Morgana.png);"></view>
			<view class="content">
				<view class=""><view class="text-cut ">DY66666672021102915400212</view></view>
				<view class="text-gray text-sm flex"> <view class="text-cut">2021-02-03 12:12:23</view></view>
			</view>
			<view class="action">
				<view class="text-grey text-xs"></view>
				<view class="cu-tag round bg-red sm">￥0.12</view>
			</view>
		</view>
		<view class="cu-item ">
			<view class="cu-avatar radius lg" style="background-image:url(https://ossweb-img.qq.com/images/lol/img/champion/Morgana.png);"></view>
			<view class="content">
				<view class=""><view class="text-cut ">DY66666672021102915400212</view></view>
				<view class="text-gray text-sm flex"> <view class="text-cut">2021-02-03 12:12:23</view></view>
			</view>
			<view class="action">
				<view class="text-grey text-xs"></view>
				<view class="cu-tag round bg-red sm">￥0.12</view>
			</view>
		</view>
		-->
			<!--加载loadding-->
			<tui-loadmore :visible="loadding"></tui-loadmore>
			<tui-nomore :visible="!pullUpOnLast" bgcolor="#ffffff"></tui-nomore>
			<!--加载loadding-->
		</view>
	</view>
</template>

<script>
import tuiLoading from '../../../components/loading/loading';
import tuiLoadmore from '../../../components/loadmore/loadmore';
import tuiNomore from '../../../components/nomore/nomore';

const http = require('../../../utils/http.js');

const Constants = require('../../../utils/constants');

export default {
    components: {
        tuiLoading,
        tuiLoadmore,
        tuiNomore
    },
    data() {
        return {
			dtype:1,
            title: {},
            status: 1,
            loadding: false,
            listData: [],
            pullUpOnLast: true,
        };
    },
    onLoad: function (options) {
        console.log(options);
        let title = '广告收益信息';
        let title2 = '待结算';

        if (options.status == 1) {
            title = '待结算收益';
			title2 = '待结算';
        } else {
            if (options.status == 2) {
                title = '已结算收益';
                title2 = '已结算';
            } else {
                if (options.status == 3) {
                    title = '已打款收益';
                    title2 = '已打款';
                }
            }
        }

        uni.setNavigationBarTitle({
            title: title
        });
        this.setData({
            title: title2,
            status: options.status,
			dtype: options.dtype
        });
		
		if(this.dtype == 1){
			this.list(false);
		}else if(this.dtype == 2){
			this.listYq(false);
		}else{
			this.listAll(false);
		}
        
    },
    onPullDownRefresh: function () {},
    onReachBottom: function () {
        if (!this.pullUpOnLast) {
            return;
        }
		if(this.dtype == 1){
			this.list(false);
		}else if(this.dtype == 2){
			this.listYq(false);
		}else{
			this.listAll(false);
		}

    },
    methods: {
		tabSelect: function (e) {
		    let dtype = e.currentTarget.dataset.dtype;
		    if (this.dtype == dtype) {
		        return false;
		    }
		    this.setData({
		        dtype: dtype,
				pageNum: 1,
				listData:[]
		    });
			
			if(this.dtype == 1){
				this.list(true);
			}else if(this.dtype == 2){
				this.listYq(true);
			}else{
				this.listAll(true);
			}
		    
		    //this.loadPostLast(true);
		},
        jumpClick: function (e) {
            let link = e.currentTarget.dataset.link;
            console.log(link);
            uni.navigateTo({
                url: link,
                // 指定页面的 url
                success: (res) => {},
                fail: (res) => {}
            });
        },

        list: function (refresh) {
            let that = this;
            that.setData({
                loadding: true
            });
            let offset = 0;

            if (!refresh) {
                offset = that.listData.length;
            }
			uni.showLoading({
				title:'加载中'
			})
            var params = {
                url: '/p/balance/list',
                method: 'GET',
                data: {
                    offset: offset,
                    status: that.status,
                    dataType: 1
                },
                callBack: function (res) {
                    that.setData({
                        loadding: false,
                        listData: refresh ? res.data.list : that.listData.concat(res.data.list),
                        pullUpOnLast: !res.data.isLastPage ? true : false
                    });
					uni.hideLoading()
                }
            };
            http.request(params);
        },
		
		// 邀请收益数据
		listYq: function (refresh) {
		    let that = this;
		    that.setData({
		        loadding: true
		    });
		    let offset = 0;
		
		    if (!refresh) {
		        offset = that.listData.length;
		    }
			uni.showLoading({
				title:'加载中'
			})
		    var params = {
		        url: '/u/distributionProfit/list',
		        method: 'GET',
		        data: {
		            offset: offset,
		            status: that.status
		        },
		        callBack: function (res) {
		            that.setData({
		                loadding: false,
		                listData: refresh ? res.data.list : that.listData.concat(res.data.list),
		                pullUpOnLast: !res.data.isLastPage ? true : false
		            });
					uni.hideLoading()
		        }
		    };
		    http.request(params);
		},
		
		// 邀请收益数据h 和广告收益
		listAll: function (refresh) {
		    let that = this;
		    that.setData({
		        loadding: true
		    });
		    let offset = 0;
		
		    if (!refresh) {
		        offset = that.listData.length;
		    }
			uni.showLoading({
				title:'加载中'
			})
		    var params = {
		        url: '/u/distributionProfit/selectAllProfitList',
		        method: 'GET',
		        data: {
		            offset: offset,
		            status: that.status
		        },
		        callBack: function (res) {
		            that.setData({
		                loadding: false,
		                listData: refresh ? res.data.list : that.listData.concat(res.data.list),
		                pullUpOnLast: !res.data.isLastPage ? true : false
		            });
					uni.hideLoading()
		        }
		    };
		    http.request(params);
		},
		
    }
};
</script>
<style>
@import './adprofit.css';
</style>
